001    /*
002     * ScoringScheme.java
003     *
004     * Copyright 2003 Sergio Anibal de Carvalho Junior
005     *
006     * This file is part of NeoBio.
007     *
008     * NeoBio is free software; you can redistribute it and/or modify it under the terms of
009     * the GNU General Public License as published by the Free Software Foundation; either
010     * version 2 of the License, or (at your option) any later version.
011     *
012     * NeoBio is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
013     * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
014     * PURPOSE. See the GNU General Public License for more details.
015     *
016     * You should have received a copy of the GNU General Public License along with NeoBio;
017     * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
018     * Boston, MA 02111-1307, USA.
019     *
020     * Proper attribution of the author as the source of the software would be appreciated.
021     *
022     * Sergio Anibal de Carvalho Junior             mailto:sergioanibaljr@users.sourceforge.net
023     * Department of Computer Science               http://www.dcs.kcl.ac.uk
024     * King's College London, UK                    http://www.kcl.ac.uk
025     *
026     * Please visit http://neobio.sourceforge.net
027     *
028     * This project was supervised by Professor Maxime Crochemore.
029     *
030     */
031    
032    package neobio.alignment;
033    
034    /**
035     * This abstract class is the superclass of all scoring schemes. It defines basic
036     * operations that must be provided by all subclasses. Scoring schemes are used by
037     * sequence alignment algorithms to compute the score of an alignment.
038     *
039     * @author Sergio A. de Carvalho Jr.
040     * @see PairwiseAlignmentAlgorithm
041     */
042    public abstract class ScoringScheme
043    {
044            /**
045             * Determines whether this scoring scheme ignores the case of characters when
046             * computing their score. It is set by the constructor and cannot be changed
047             * afterwards.
048             */
049            protected boolean case_sensitive;
050    
051            /**
052             * Creates a new instance of an scoring scheme. The case of characters is significant
053             * when subsequently computing their score.
054             */
055            public ScoringScheme ()
056            {
057                    this (true);
058            }
059    
060            /**
061             * Creates a new instance of an scoring scheme. If <CODE>case_sensitive</CODE> is
062             * <CODE>true</CODE>, the case of characters is significant when subsequently
063             * computing their score; otherwise the case is ignored.
064             *
065             * @param case_sensitive <CODE>true</CODE> if the case of characters must be
066             * significant, <CODE>false</CODE> otherwise
067             */
068            public ScoringScheme (boolean case_sensitive)
069            {
070                    this.case_sensitive = case_sensitive;
071            }
072    
073            /**
074             * Tells whether this scoring scheme ignores the case of characters when computing
075             * their score.
076             *
077             * @return <CODE>true</CODE> if the case of characters is significant,
078             * <CODE>false</CODE> otherwise
079             */
080            public boolean isCaseSensitive ()
081            {
082                    return this.case_sensitive;
083            }
084    
085            /**
086             * Returns the score of a substitution of character <CODE>a</CODE> for character
087             * <CODE>b</CODE> according to this scoring scheme. If this substitution is not
088             * defined, an exception is raised.
089             *
090             * @param a first character
091             * @param b second character
092             * @return score of substitution of <CODE>a</CODE> for <CODE>b</CODE>
093             * @throws IncompatibleScoringSchemeException if this substitution is not defined
094             */
095            public abstract int scoreSubstitution (char a, char b)
096                    throws IncompatibleScoringSchemeException;
097    
098            /**
099             * Returns the score of an insertion of character <CODE>a</CODE> according to this
100             * scoring scheme. If this character is not recognised, an exception is raised.
101             *
102             * @param a the character to be inserted
103             * @return score of insertion of <CODE>a</CODE>
104             * @throws IncompatibleScoringSchemeException if character is not recognised by this
105             * scoring scheme
106             */
107            public abstract int scoreInsertion (char a)
108                    throws IncompatibleScoringSchemeException;
109    
110            /**
111             * Returns the score of a deletion of character <CODE>a</CODE> according to this
112             * scoring scheme. If this character is not recognised, an exception is raised.
113             *
114             * @param a the character to be deleted
115             * @return score of insertion of <CODE>a</CODE>
116             * @throws IncompatibleScoringSchemeException if character is not recognised by this
117             * scoring scheme
118             */
119            public abstract int scoreDeletion (char a)
120                    throws IncompatibleScoringSchemeException;
121    
122            /**
123             * Returns the maximum absolute score that this scoring scheme can return for any
124             * substitution, deletion or insertion.
125             *
126             * @return maximum absolute score that can be returned
127             */
128            public abstract int maxAbsoluteScore ();
129    
130            /**
131             * Returns <CODE>true</CODE> if this scoring scheme supports partial matches,
132             * <CODE>false</CODE> otherwise. A partial match is a situation when two characters
133             * are not equal but, for any reason, are regarded as similar by this scoring scheme,
134             * which then returns a positive score. This is common when for scoring schemes
135             * that implement amino acid scoring matrices.
136             *
137             * @return <CODE>true</CODE> if this scoring scheme supports partial matches,
138             * <CODE>false</CODE> otherwise
139             */
140            public abstract boolean isPartialMatchSupported ();
141    }